﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using MusicLibrary.Models;

namespace MusicLibrary.Controllers
{
	public class HomeController : Controller
	{
		private readonly MusicLibraryEntities _storeDb = new MusicLibraryEntities();
		public ActionResult Index ()
		{
			ViewBag.Message = "Welcome to ASP.NET MVC!";
			var albums = GetTopSellingAlbums(5);
			return View(albums);
		}

		public ActionResult About ()
		{
			return View();
		}

		private List<Album> GetTopSellingAlbums (int count)
		{
			return _storeDb.Albums.
				OrderByDescending(a => a.OrderDetails.Count()).
				Take(count).
				ToList();
		}
	}
}
